package it.polimi.digitalstate.entities;

import it.polimi.digitalstate.entities.Citizen;
import it.polimi.digitalstate.entities.Party;

import java.io.Serializable;
import java.lang.String;
import java.sql.Date;

import javax.persistence.*;

import it.polimi.digitalstate.dto.ElectionVoteDTO;
import it.polimi.digitalstate.dto.IDataTransferObject;

/**
 * Entity implementation class for Entity: electionvote
 *
 */
@Entity
@NamedQueries(value = { 
		@NamedQuery(name = "electionvote_getByID", query = "select j from ElectionVote j where j.id = :id" ),
		@NamedQuery(name = "electionvote_getOnCitizen", query = "select j from ElectionVote j where j.p1 = :citizen or j.p2 = :citizen or j.p3 = :citizen" ),
		@NamedQuery(name = "electionvote_getAllOnParty", query = "select j from ElectionVote j where j.party = :party" ),
		@NamedQuery(name = "electionvote_votedbefore", query = "select j from ElectionVote j where j.citizen = :citizen and j.election = :election" ),
		@NamedQuery(name = "electionvote_getByElection", query = "select j from ElectionVote j where j.election = :election" ),
		
	})
/*@Table(uniqueConstraints= @UniqueConstraint(columnNames = {"citizen", "election"})) /*only one vote per election*/ 
public class ElectionVote implements Serializable , IEntity {
	//TODO create the DTO
	//TODO set a Constructor with a DTO and set a method that retrieve the DTO
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	@JoinColumn(nullable=false)
	private Citizen citizen;
	@JoinColumn(nullable=false)
	private Party party;
	@JoinColumn(nullable=false)
	private Citizen p1;
	@JoinColumn
	private Citizen p2;
	@JoinColumn
	private Citizen p3;
	private Date vote_date;
	@JoinColumn(nullable=false)
	private Election election;
	private static final long serialVersionUID = 1L;

	public ElectionVote() {
		super();
	}   
	public ElectionVote(Citizen citizen, Party party, Citizen p1, Citizen p2, Citizen p3, Date vote_date, Election election){
		super();
		this.citizen = citizen;
		this.party=party;
		this.p1=p1;
		this.p2=p2;
		this.p3=p3;
		this.vote_date=vote_date;
		this.election = election;
	}
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	public Citizen getCitizen() {
		return this.citizen;
	}

	public void setCitizen(Citizen citizen) {
		this.citizen = citizen;
	}   
	public Party getParty() {
		return this.party;
	}

	public void setParty(Party party) {
		this.party = party;
	}   
	public Citizen getP1() {
		return p1;
	}
	public void setP1(Citizen p1) {
		this.p1 = p1;
	}
	public Citizen getP2() {
		return p2;
	}
	public void setP2(Citizen p2) {
		this.p2 = p2;
	}
	public Citizen getP3() {
		return p3;
	}
	public void setP3(Citizen p3) {
		this.p3 = citizen;
	}
	
	public Date getVote_date() {
		return vote_date;
	}
	public void setVote_date(Date vote_date) {
		this.vote_date = vote_date;
	}
	@Override
	public IDataTransferObject getDTO() {
		return new ElectionVoteDTO(id, citizen.getDTO(), party.getDTO(), p1.getDTO(), (p2 == null)? null :p2.getDTO(), (p3 == null)? null:p3.getDTO(), vote_date, election.getDTO());
	}
	public Election getElection() {
		return election;
	}
	public void setElection(Election election) {
		this.election = election;
	}
   
}
